package com.ggh.controller;
import com.ggh.entity.Airlines;
import com.ggh.entity.TypeBean;
import com.ggh.service.AirlinesService;
import com.ggh.vo.Body;
import com.ggh.vo.UserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @author jj
 * @date 2019/10/15 11:30
 * 客服
 */
@Controller
@RequestMapping(value = "/Airlines")
public class AirlinesController {
    @Autowired
    private AirlinesService airlinesService;
    /**
     * @description :添加客服
     * @param airlines
     * @return: java.util.List<com.ggh.entity.Airlines>
     * @date : 2019/10/14 15:44
     * @author : jj
     * @throws
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Body add(Airlines airlines) {
        Body body = airlinesService.add(airlines);
        return body;
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.POST)
    @ResponseBody
    public  UserToken  fandAll(Integer userid,Integer type) {
        List<Airlines> airlinesList = airlinesService.list(null);
        //联系客服
        if (type==1){
            return UserToken.newInstance(userid,"HallKeFu",airlinesList, TypeBean.SUCCESS);
        }

        //提现，充值客服
        return UserToken.newInstance(userid,"HallWXCustomer",airlinesList, TypeBean.SUCCESS);
    }
    /**
     * 删除客服
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Body delete(Airlines airlines) {
        Body body = airlinesService.delete(airlines);
        return body;
    }
    /**
     * 更新客服
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Body update(Airlines airlines) {
        boolean isUpdated = airlinesService.saveOrUpdate(airlines);
        if (!isUpdated){
            return Body.newInstance(500,"参数错误！");
        }
        return Body.newInstance();
    }
}
